@extends("layout.admin")

@section("title")
    岗位列表
@endsection

@section("content")
    {{--列表--}}
    <div class="layui-card-body ">
        <form id="search-form">
            <input type="hidden" name="group_id" value="{{request('group_id')}}">
        </form>
        <script type="text/html" id="toolbar">
            <div class="layui-btn-container">
                @if(_can('admin.post.create'))<a class="layui-btn layui-btn-sm" onclick="admin.openLayerForm('{{route("admin.post.create.attach",["group_id"=>request("group_id")])}}', '添加岗位', 'POST', '600px', '450px')"><i class="layui-icon"></i>添加岗位</a>@endif
                <a class="layui-btn layui-btn-sm" onclick="window.location.href='{{ route("admin.post.index") }}'">返回</a>
            </div>
        </script>
        <table lay-filter="table-hide" style="display: none"  lay-data="{height:'full-310', cellMinWidth: 80,toolbar: '#toolbar',defaultToolbar:['filter'],limit:{{$data['per_page']}}}">
            <thead>
            <tr>
                <th lay-data="{field:'id',width:80, fixed: 'left', unresize: true, sort: true}">编号</th>
                <th lay-data="{field:'group_name'}">分组名称</th>
                <th lay-data="{field:'name'}">名称</th>
                <th lay-data="{field:'sort',edit: 'text'}">排序</th>
                <th lay-data="{field:'created_at'}">创建时间</th>
                <th lay-data="{field:'updated_at'}">更新时间</th>
                <th lay-data="{field:'op',fixed: 'right', width:220, align:'center'}">操作</th>
            </tr>
            </thead>
            <tbody>
            @foreach ($data['data'] as $vo)
                <tr>
                    <td>{{ $vo['id'] }}</td>
                    <td>{{ $vo['group_name'] }}</td>
                    <td>{{ $vo['name'] }}</td>
                    <td>{{ $vo['sort'] }}</td>
                    <td>{{ $vo['created_at'] }}</td>
                    <td>{{ $vo['updated_at'] }}</td>
                    <td>
                        @if(_can('admin.post.update'))<a class="layui-btn layui-btn-xs" onclick="admin.openLayerForm('{{ route("admin.post.update.attach",['id' => $vo['id']]) }}', '编辑', 'POST', '600px', '450px')">编辑</a>@endif
                        @if(_can('admin.post.destroy'))<a class="layui-btn layui-btn-xs layui-btn-danger" onclick="admin.tableDataDelete('{{ route("admin.post.destroy.attach", ['id' => $vo['id']]) }}', this,'确认删除吗')">删除</a>@endif
                    </td>
                </tr>
            @endforeach
            </tbody>
        </table>
        @include("layout.page")
    </div>
@endsection

@section('script')
    <script>
        var idx=-1;
        layui.use(['form', 'table', 'layer'], function () {
            var table = layui.table;
            var form = layui.form;
            table.init("table-hide");
            table.on('edit(table-hide)', function(obj){
                var value = obj.value
                var id = obj.data.id
                $.post("{{route('admin.post.changeSort.attach')}}",{id:id,value:value,_token:'{{ csrf_token() }}'},function(data){
                    if(data <= 0){
                        layer.msg("操作失败",{icon:5})
                    }
                })
            });
            admin.paginate("{{ $data['total'] }}", "{{ $data['current_page'] }}", "{{ $data['per_page'] }}");
        });
    </script>
    <script src="{{asset('js/layCommon.js')}}"></script>
@endsection

